﻿using System;
using System.Diagnostics;

namespace Alogrithm
{
    internal class Program
    {
        private const int randCount = 10000;

        static void Main(string[] args)
        {
            // var arr =GetRandNumbers();
            //PrintBubble(arr);
            //PrintInsertion(arr);
            //PrintMerge(arr);
            while (Console.ReadKey().Key.ToString() == "Y")
            {
                var arr = GetQueue();
                /*arr = new int[][]
                {
                    new int[] {0, 0}, new int[] {2, 0}, new int[] {1, 2}, new int[] {2, 4}, new int[] {0, 5},
                    new int[] {2, 3}
                };*/
                var queue = new PriorityQueue();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                var r = queue.GetOrder(arr);
                Console.WriteLine("Stopwatch总共花费{0}ms.", sw.Elapsed.TotalMilliseconds);
                //PrintQueue(r);
                //Console.ReadKey();
            }


        }

        static void PrintBubble(int[] arr)
        {
            Console.WriteLine("***************************************");
            Console.WriteLine("冒泡排序");
            NumberSort.Bubble(arr);
            foreach (var item in arr)
            {
                Console.Write(item + ",");
            }

            Console.WriteLine();
            Console.WriteLine("***************************************");
        }

        static void PrintInsertion(int[] arr)
        {
            Console.WriteLine("***************************************");
            Console.WriteLine("插入排序");
            NumberSort.Insertion(arr);
            foreach (var item in arr)
            {
                Console.Write(item + ",");
            }

            Console.WriteLine();
            Console.WriteLine("***************************************");
        }

        static void PrintMerge(int[] arr)
        {
            Console.WriteLine("***************************************");
            Console.WriteLine("并柜排序");
            NumberSort.Merge(arr);
            foreach (var item in arr)
            {
                Console.Write(item + ",");
            }

            Console.WriteLine();
            Console.WriteLine("***************************************");
        }

        static void PrintQueue(int[] arr)
        {
            Console.WriteLine("***************************************");

            foreach (var t in arr)
            {
                Console.Write(t + ",");
            }

            Console.WriteLine();
            Console.WriteLine("***************************************");
        }

        static int[] GetRandNumbers()
        {
            Console.WriteLine("***************************************");
            var rand = new Random();
            var arr = new int[randCount];
            for (int i = 0; i < randCount; i++)
            {
                arr[i] = rand.Next(0, randCount);
                Console.Write(arr[i] + ",");
            }

            Console.WriteLine();
            Console.WriteLine("***************************************");
            return arr;
        }

        static int[][] GetQueue()
        {
            Console.WriteLine("***************************************");
            var rand = new Random();
            var arr = new int[randCount][];
            var str1 = string.Empty;
            var str2 = string.Empty;
            for (var i = 0; i < randCount; i++)
            {
                arr[i] = new int[] { rand.Next(0, randCount / 2), 1 };
                str1 += "|" + arr[i][0] + "," + arr[i][1] + "|";
                str2 += "  " + i + "  ";
            }

            Console.WriteLine(str1);
            Console.WriteLine(str2);
            Console.WriteLine();
            Console.WriteLine("***************************************");
            return arr;
        }
    }
}